<?php
/* config file for general configs */
require_once("../config.php");

/* use the database for queries */
require_once("../class/database.class.php");

// blog class for site ident
require_once("../class/blog.class.php");

/* nusoap library for SOAP */
require_once("../lib/Nusoap/nusoap.php");

/* article service api server */
$soap = new soap_server;

// we need the blog here to get CDN primary domain
$b = new blog($_SERVER["HTTP_HOST"]);

// configure the WSDL to show up on ?wsdl requests
$soap->configureWSDL('ArticleApiService', "http://".CONFIG_CDN_PRIMARY_DOMAIN."/");

// define soap interop as default standard schema
$soap->wsdl->schemaTargetNamespace = 'http://soapinterop.org/xsd/';

// add the complex type for the article itself
$soap->wsdl->addComplexType(
    'articleList',
    'complexType',
    'array',
    'all',
    '',
    array(
     'articleTitle'=>array('name'=>'articleTitle','type'=>'xsd:string'),
     'articleBody'=>array('name'=>'articleBody','type'=>'xsd:string'),
     'articleLink'=>array('name'=>'articleLink','type'=>'xsd:string'))
);


// register the methods
$soap->register(
    'getArticleList',
    array(), array('List' => 'tns:articleList'),
    'http://soapinterop.org/'
);

$soap->service(isset($HTTP_RAW_POST_DATA) ?
    $HTTP_RAW_POST_DATA : '');


/* getArticleList method implementation */
function getArticleList() {
	$articeList = array(); // result object
	
	$db = new database();
	$db->setSite($db->getSiteIdByDomain($_SERVER["HTTP_HOST"]));
	$dblist = $db->getArticleList();
	for($a=0;$a<count($dblist);$a++){
		$dbarticle = $db->getArticle($dblist[$a]["url"]);
		$articeList[$a] = array("articleTitle" => $dbarticle["title"], 
							"articleBody" => $dbarticle["body"],
							"articleLink" => "http://".CONFIG_CDN_PRIMARY_DOMAIN
												."/".$dbarticle["url"].".html");
	}

	return $articeList; // return result
}
?>